package com.xxtx.trade.common.utils;

import com.xxtx.trade.common.util.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@Component
public class SendEamil {
    @Autowired
    private JavaMailSender mailSender;
    /**
     *
     * @param sender 发送人
     * @param receivrer 接收人
     * @param title 标题
     * @param remark 内容
     * @param otherEmail 抄送人
     * @return
     */
    public  Result sendQQEmail(String sender,String receivrer,String title,String remark,String otherEmail){
        try {

            SimpleMailMessage message = new SimpleMailMessage();
            // 发件人
            message.setFrom(sender);
            // 收件人
            message.setTo(receivrer);
            // 邮件标题
            message.setSubject(title);
            // 邮件内容
            message.setText(remark);
            // 抄送人
           if (otherEmail!=null){
               message.setCc(otherEmail);
           }
            mailSender.send(message);
            return Result.success();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error("发送失败"+e.getMessage());
        }
    }

}
